package com.ruoyi.kong.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kong.domain.KCmdSet;
import com.ruoyi.kong.service.IKCmdSetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 命令集Controller
 * 
 * @author zeroUp
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/kong/cmdset")
public class KCmdSetController extends BaseController
{
    @Autowired
    private IKCmdSetService kCmdSetService;

    /**
     * 查询命令集列表
     */
    @PreAuthorize("@ss.hasPermi('kong:cmdset:list')")
    @GetMapping("/list")
    public TableDataInfo list(KCmdSet kCmdSet)
    {
        startPage();
        List<KCmdSet> list = kCmdSetService.selectKCmdSetList(kCmdSet);
        return getDataTable(list);
    }

    /**
     * 导出命令集列表
     */
    @PreAuthorize("@ss.hasPermi('kong:cmdset:export')")
    @Log(title = "命令集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KCmdSet kCmdSet)
    {
        kCmdSet.setCreateBy(SecurityUtils.getUserId().toString());
        List<KCmdSet> list = kCmdSetService.selectKCmdSetList(kCmdSet);
        ExcelUtil<KCmdSet> util = new ExcelUtil<KCmdSet>(KCmdSet.class);
        util.exportExcel(response, list, "命令集数据");
    }

    /**
     * 获取命令集详细信息
     */
    @PreAuthorize("@ss.hasPermi('kong:cmdset:query')")
    @GetMapping(value = "/{gid}")
    public AjaxResult getInfo(@PathVariable("gid") Long gid)
    {
        return success(kCmdSetService.selectKCmdSetByGid(gid));
    }

    /**
     * 新增命令集
     */
    @PreAuthorize("@ss.hasPermi('kong:cmdset:add')")
    @Log(title = "命令集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KCmdSet kCmdSet)
    {
        return toAjax(kCmdSetService.insertKCmdSet(kCmdSet));
    }

    /**
     * 修改命令集
     */
    @PreAuthorize("@ss.hasPermi('kong:cmdset:edit')")
    @Log(title = "命令集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KCmdSet kCmdSet)
    {
        return toAjax(kCmdSetService.updateKCmdSet(kCmdSet));
    }

    /**
     * 删除命令集
     */
    @PreAuthorize("@ss.hasPermi('kong:cmdset:remove')")
    @Log(title = "命令集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gids}")
    public AjaxResult remove(@PathVariable Long[] gids)
    {
        return toAjax(kCmdSetService.deleteKCmdSetByGids(gids));
    }
}
